Micron Document
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| SparkN0de-git | SparkN0de |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Displaying Raw • Download


sbapp/pyogg/audio_file.py 0.9.0 (50011dc7) Text, 1.85 KB

Tff7b72from T7ee787.T7ee787pyogg_error Tff7b72import Te6edf3PyOggError

Tff7b72class T56d364AudioFileTb4b4b4:
T8b949e"""Abstract base class for audio files.

This class is a base class for audio files (such as Vorbis, Opus,
and FLAC). It should not be instatiated directly.
"""

Tff7b72def Tff7b72__init__Tb4b4b4(Tff7b72selfTb4b4b4)Tb4b4b4:
Tff7b72raise Te6edf3PyOggErrorTb4b4b4(Ta5d6ff"Ta5d6ffAudioFile is an Abstract Base Class Ta5d6ff"Tff7b72+
Ta5d6ff"Ta5d6ffand should not be instantiatedTa5d6ff"Tb4b4b4)
Tff7b72def Td2a8ffas_arrayTb4b4b4(Tff7b72selfTb4b4b4)Tb4b4b4:
T8b949e"""Returns the buffer as a NumPy array.

The shape of the returned array is in units of (number of
samples per channel, number of channels).

The data type is either 8-bit or 16-bit signed integers,
depending on bytes_per_sample.

The buffer is not copied, but rather the NumPy array
shares the memory with the buffer.

"""
T8b949e# Assumes that self.buffer is a one-dimensional array of
T8b949e# bytes and that channels are interleaved.
Tff7b72import T7ee787numpy T8b949e# type: ignore
Tff7b72assert Tff7b72selfTff7b72.Td2a8ffbuffer Tff7b72is Tff7b72not Tff7b72None
Tff7b72assert Tff7b72selfTff7b72.Td2a8ffchannels Tff7b72is Tff7b72not Tff7b72None

T8b949e# The following code assumes that the bytes in the buffer
T8b949e# represent 8-bit or 16-bit signed ints. Ensure the number of
T8b949e# bytes per sample matches that assumption.
Tff7b72assert Tff7b72selfTff7b72.Td2a8ffbytes_per_sample Tff7b72== T79c0ff1 Tff7b72or Tff7b72selfTff7b72.Td2a8ffbytes_per_sample Tff7b72== T79c0ff2

T8b949e# Create a dictionary mapping bytes per sample to numpy data
T8b949e# types
Te6edf3dtype Tff7b72= Tb4b4b4{
T79c0ff1Tb4b4b4: Te6edf3numpyTff7b72.Td2a8ffint8Tb4b4b4,
T79c0ff2Tb4b4b4: Te6edf3numpyTff7b72.Td2a8ffint16
Tb4b4b4}
T8b949e# Convert the ctypes buffer to a NumPy array
Te6edf3array Tff7b72= Te6edf3numpyTff7b72.Td2a8fffrombufferTb4b4b4(
Tff7b72selfTff7b72.Td2a8ffbufferTb4b4b4,
Te6edf3dtypeTff7b72=Te6edf3dtypeTb4b4b4[Tff7b72selfTff7b72.Td2a8ffbytes_per_sampleTb4b4b4]
Tb4b4b4)

T8b949e# Reshape the array
Tff7b72return Te6edf3arrayTff7b72.Td2a8ffreshapeTb4b4b4(
Tb4b4b4(Tffa657lenTb4b4b4(Tff7b72selfTff7b72.Td2a8ffbufferTb4b4b4)
Tff7b72/Tff7b72/ Tff7b72selfTff7b72.Td2a8ffbytes_per_sample
Tff7b72/Tff7b72/ Tff7b72selfTff7b72.Td2a8ffchannelsTb4b4b4,
Tff7b72selfTff7b72.Td2a8ffchannelsTb4b4b4)
Tb4b4b4)


──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────